import requests
import re
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0'}
url = 'https://movie.douban.com/top250'
resp = requests.get(url, headers=headers)
html = resp.text
soup = BeautifulSoup(html, 'lxml')
names = []
scores = []
for div in soup.find_all('div', class_='hd'):
    name_span = div.find('span', class_='title')
    name = name_span.string
    names.append(name)
for span in soup.find_all('span', class_='rating_num'):
    score = span.string
    scores.append(score)
spans = soup.find_all('span')
nums = []
for span in spans:
    match = re.search(r'(\d+)人评价', span.get_text())
    if match:
        nums.append(match.group(1))
if nums:
    print(nums)
print(len(names))
print(len(scores))
print(len(nums))
for name, score, num in zip(names, scores, nums):
    print(f"电影名: {name}, 评分: {score}, 评论人数: {num}")